package com.alarmgame.alert;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.widget.Toast;

import com.alarmgame.R;
import com.alarmgame.application.MainApplication;
import com.alarmgame.webview.AlarmWebView;
/**
 * 
 * Alarm Game Alert.
 * 
 * @author EJ
 *
 */
public class AlarmGameAlert extends Activity {
	
	private MediaPlayer mPlayer = null;

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.alert_layout);
		
		// Create a dialog that the user must dismiss
		AlertDialog alertDialog = new AlertDialog.Builder(this).create();
		alertDialog.setMessage("Detener Alarma");

		alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
			public void onClick(DialogInterface dialog, int which) {
				Intent alarmWebView = new Intent(Intent.ACTION_VIEW);
				alarmWebView.setClass(getBaseContext(), AlarmWebView.class);
				alarmWebView.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
				startActivity(alarmWebView);
			}
		});
		alertDialog.setIcon(R.drawable.icon);
		alertDialog.show();
	}
	
	@Override
	protected void onPostResume() {
		super.onPostResume();
		mPlayer = MediaPlayer.create(getBaseContext(), R.raw.alarm_clock1);
		mPlayer.start();
		mPlayer.setLooping(Boolean.TRUE);
		MainApplication mainApplication = ((MainApplication)getApplicationContext());
		mainApplication.setAlarm(mPlayer);
		mainApplication.setAlertClose(this);
	}
}